package org.example.config;

import org.example.filter.CORSFilter;
import org.example.interceptors.FmBackendJwtTokenInterceptor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;

@Configuration
public class FmBackendWebConfig implements WebMvcConfigurer {
    private FmBackendJwtTokenInterceptor fmBackendJwtTokenInterceptor;

    public FmBackendWebConfig(FmBackendJwtTokenInterceptor fmBackendJwtTokenInterceptor) {
        this.fmBackendJwtTokenInterceptor = fmBackendJwtTokenInterceptor;
    }

    @Bean
    public FilterRegistrationBean<CORSFilter> corsFilterFilterRegistrationBean(){
        FilterRegistrationBean<CORSFilter> bean=new FilterRegistrationBean<>();
        bean.setFilter(new CORSFilter());
        bean.setUrlPatterns(Arrays.asList("/*"));
        bean.setOrder(1);
        return bean;
    }
    //添加拦截器

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(fmBackendJwtTokenInterceptor)
//                .addPathPatterns("/**")//拦截什么
                .excludePathPatterns("/**");//不拦什么
    }
}
